package com.atguigu.controller;

import com.atguigu.util.SecKill_redis1;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Random;

/**
 * 处理秒杀请求的控制器
 */
@Controller
public class SecKillController {

	@ResponseBody
	@RequestMapping("/doseckill")
	protected String doseckill(String prodid,HttpServletRequest request, HttpServletResponse response) throws Exception {

		String userid = new Random().nextInt(50000) +"" ; 

		boolean if_success= SecKill_redis1.doSecKill(userid,prodid); //实验1:存在超卖情况
		//boolean if_success= SecKill_redis2.doSecKill(userid,prodid); //实验2:解决超卖问题，但存在遗留库存和连接超时问题
		//boolean if_success=SecKill_redis3.doSecKill(userid,prodid); //实验3:连接池解决超时问题
		//boolean if_success=SecKill_redisByScript.doSecKill(userid,prodid); //实验4:采用LUA脚本，解决库存遗留问题
 
		return Boolean.toString(if_success);

	}
	public void gitTest(){
		System.out.println("true = " + true);


	}

	public void testGit(){
		System.out.println("git练习1");
		System.out.println("git练习");
	}



}
